﻿using WarehouseManagementSystem.Entities;
using WarehouseManagementSystem.Services.IServices;

namespace WarehouseManagementSystem.DAL;

public class CargoRepository(ISqliteService sqliteService) : RepositoryBase(sqliteService),IRepository<Cargo>
{
    public async Task<int> Insert(Cargo entity) => await db.InsertAsync(entity);

    public async Task<int> Update(Cargo entity) => await db.UpdateAsync(entity);

    public async Task<int> Delete(Cargo entity) => await db.DeleteAsync(entity);
    
    public async Task<List<Cargo>> GetAll() => await db.Table<Cargo>().ToListAsync();

    public Task<List<Cargo>> FindAll(string keyWords) 
        => db.Table<Cargo>().Where(x => x.Name.Contains(keyWords)).ToListAsync();

    public async Task<Cargo> FindFirst(string keyWords)
        => await db.Table<Cargo>().FirstAsync(x => x.Name.Equals(keyWords, StringComparison.OrdinalIgnoreCase));
}